TARGET	= libnet.a
OUTDIR	= lib
OBJDIR	= $(BUILDDIR)/libnet

SEARCH	= . protocols

SRCS	= $(foreach PATH, $(SEARCH), $(wildcard $(PATH)/*.cc))
OBJS	= $(patsubst %.cc, $(OBJDIR)/%.o, $(SRCS))
DIRS	= $(sort $(patsubst %/, %, $(dir $(OBJS)))) $(OUTDIR)

all: prebuild build

prebuild:
	@echo -e '\033[35m=== Start build $(TARGET) ...\033[0m'
	@test -d '$(DIRS)' | mkdir -p $(DIRS)

build: $(OBJS)
	@echo -e '\033[36mGenerate $(OUTDIR)/$(TARGET) ... \033[0m'
	@ar -rcs $(OUTDIR)/$(TARGET) $(OBJS)

clean:
	@rm -f $(OBJS) $(OUTDIR)/$(TARGET)

$(OBJDIR)/%.o: %.cc
	@echo -e '\033[33m--> Compile $< ...\033[0m'
	@$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCLUDES)